---------------------------------------
----SpaceRace Menu - Top Times Tab-----
---------------------------------------

if SR_DEBUG then print("SR: cl_menu_toptimes loaded") end

--SRMenuTabTimes = {}

print("SR: cl_menu_toptimes test")

TopTimesTable = {}

usermessage.Hook( "TopTimesTable", function( Times )
TopTimesTable = Times:ReadFloat() or 0; end )

function SRMenu_TopTimes_hook( um )
    local num_lines = um:ReadLong()
    Msg( "Number of times: " .. num_lines .. "\n")
    
    for i=1, num_lines do
        local Name = um:ReadString()
        local Time = um:ReadFloat()
        TopTimesTable[Name] = Time
        Msg( "Line: " .. i .. ": Name: " .. Name .. ": Time: " .. Time .. "\n" ) -- Print each line
    end

end
usermessage.Hook("SendTimesTable", SRMenu_TopTimes_hook)

function my_variable_message_hook( um )
    local num_lines = um:ReadLong()                                -- Read number of lines.
    Msg( "Number of lines: " .. num_lines .. "\n")
    for i=1, num_lines do
        Msg( "Line " .. i .. ": \"" .. um:ReadString() .. "\"\n" ) -- Print each line
    end
end



function SRMenuTabTimes(Tabs)
    if SR_DEBUG then print("SR: cl_menu SRMenuTabTimes showing") end

    local TopScoresList = vgui.Create("DListView")
    
    TopScoresList:SetPos(SRMenuVars.Padding, SRMenuVars.Padding)
    TopScoresList:SetSize(SRScoreVars.ScoresWidth, SRScoreVars.ScoresHeight)
    --TopScoresList:SetSize(380, 380)
    TopScoresList:SetMultiSelect(false)
    TopScoresList:AddColumn("Name") -- Add column
    TopScoresList:AddColumn("Best Time")
 
    for k,v in pairs(player.GetAll()) do
        local BestTime = string.format('%1.3f',v:GetNetworkedFloat("BestTime"))
        TopScoresList:AddLine(v:Nick(),BestTime) -- Add lines
    end

    Tabs:AddSheet( "Top Times", TopScoresList, "gui/silkicons/user", false, false, "View the Top Times on this track" )

end